package com.wxx.design.enuminstance;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @author Jetwang
 * @version 1.0
 * @date 2022/4/14 19:14
 */
public class Test {
    public static void main(String[] args) throws Exception {
        EnumInstance instance = EnumInstance.getInstance();
        instance.setData(new Object());
        System.out.println(instance.getData());

        // NoSuchMethodException 反射无法破坏枚举单例
        Class objectClass = EnumInstance.class;
        Constructor constructor = objectClass.getDeclaredConstructor();
        constructor.setAccessible(true);
        EnumInstance instance1 = (EnumInstance) constructor.newInstance();
        System.out.println(instance1);
    }
}
